/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.jrk_verwaltung.security.user;

import de.jrk_verwaltung.design.personen.CPerson;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * 
 * @author JRK-FO
 */
@Entity
@Table(name = "jrk_user")
@XmlRootElement
@NamedQueries({ @NamedQuery(name = "CUser.findAll", query = "SELECT j FROM CUser j"), @NamedQuery(name = "CUser.findByIduser", query = "SELECT j FROM CUser j WHERE j.iduser = :iduser"),
        @NamedQuery(name = "CUser.findByUser", query = "SELECT j FROM CUser j WHERE j.username = :username"),
        @NamedQuery(name = "CUser.findByPassword", query = "SELECT j FROM CUser j WHERE j.password = :password"),
        @NamedQuery(name = "CUser.findByActiv", query = "SELECT j FROM CUser j WHERE j.activ = :activ") })
public class CUser implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "iduser")
    private Integer iduser;
    @Basic(optional = false)
    @Column(name = "username")
    private String username;
    @Basic(optional = false)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @Column(name = "activ")
    private boolean activ;
    @JoinColumn(name = "fk_idperson", referencedColumnName = "idperson")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private CPerson fkIdperson;

    public CUser() {
    }

    public CUser(Integer iduser) {
        this.iduser = iduser;
    }

    public CUser(Integer iduser, String user, String password, boolean activ) {
        this.iduser = iduser;
        this.username = user;
        this.password = password;
        this.activ = activ;
    }

    public Integer getIduser() {
        return iduser;
    }

    public void setIduser(Integer iduser) {
        this.iduser = iduser;
    }

    public String getUser() {
        return username;
    }

    public void setUser(String user) {
        this.username = user;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean getActiv() {
        return activ;
    }

    public void setActiv(boolean activ) {
        this.activ = activ;
    }

    public CPerson getFkIdperson() {
        return fkIdperson;
    }

    public void setFkIdperson(CPerson fkIdperson) {
        this.fkIdperson = fkIdperson;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(this.iduser).append(this.username).toHashCode();
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof CUser)) {
            return false;
        }
        CUser other = (CUser) object;
        if (this == other) {
            return true;
        }

        return new EqualsBuilder().append(this.getIduser(), other.getIduser()).isEquals();
    }

}
